package com.tj.tj_java.controller;

//装饰者模式允许向一个对象添加新的功能，而不改变其结构。
// 基本组件接口
interface Coffee {
    double cost();
    String description();
}

// 具体组件类
class SimpleCoffee implements Coffee {
    @Override
    public double cost() {
        return 5;
    }

    @Override
    public String description() {
        return "Simple Coffee";
    }
}

// 装饰者类
class MilkDecorator implements Coffee {
    private Coffee coffee;

    public MilkDecorator(Coffee coffee) {
        this.coffee = coffee;
    }

    @Override
    public double cost() {
        return coffee.cost() + 1.5;  // 添加牛奶的费用
    }

    @Override
    public String description() {
        return coffee.description() + ", Milk";  // 添加牛奶的描述
    }
}

class SugarDecorator implements Coffee {
    private Coffee coffee;

    public SugarDecorator(Coffee coffee) {
        this.coffee = coffee;
    }

    @Override
    public double cost() {
        return coffee.cost() + 0.5;  // 添加糖的费用
    }

    @Override
    public String description() {
        return coffee.description() + ", Sugar";  // 添加糖的描述
    }
}